/*
 * Conjunction.cpp
 *
 *  Created on: Apr 29, 2012
 *      Author: kobe
 */

#include "Conjunction.h"
#include "Util.h"

Conjunction::Conjunction(Proposition* left, Proposition* right) :
		Proposition(CONJUNCTION) {
	mRight = right;
	mLeft = left;
	mIsAction = false;
	if (mLeft->isAction() || mRight->isAction()) {
		mIsAction = true;
	} else {
		mIsAction = false;
	}
}

Conjunction::Conjunction(std::string input) :
		Proposition(CONJUNCTION) {
	std::string content(input, 2, input.size() - 2);
	size_t left, right;
	std::string sleft = getBracketContent(content, &left, &right);
	std::string ncontent(content, right + 2, content.size() - right - 2);
	std::string sright = getBracketContent(ncontent, &left, &right);
	mLeft = createProposition(sleft);
	mRight = createProposition(sright);
	if (mLeft->isAction() || mRight->isAction()) {
		mIsAction = true;
	} else {
		mIsAction = false;
	}
}

std::string Conjunction::toString() {
	std::string result;
	result += "cj{";
	result += mLeft->toString();
	result += "}{";
	result += mRight->toString();
	result += '}';
	return result;
}

Conjunction::~Conjunction() {
	// TODO Auto-generated destructor stub
}

Proposition *Conjunction::getLeft() const {
	return mLeft;
}

Proposition *Conjunction::getRight() const {
	return mRight;
}

bool Conjunction::compare(Proposition* p) {
	if (p->getPropName() != CONJUNCTION) {
		return false;
	} else {
		Conjunction *cj = (Conjunction*) p;
		return mLeft->compare(cj->getLeft()) && mRight->compare(cj->getRight());
	}
}

std::string Conjunction::toLatex() {
	std::string s;
	if (mLeft->getPropName() != ATOMIC && mLeft->getPropName() != ACTION) {
		s += "(";
	}
	s += mLeft->toLatex();
	if (mLeft->getPropName() != ATOMIC && mLeft->getPropName() != ACTION) {
		s += ")";
	}

	s += " \\wedge ";

	if (mRight->getPropName() != ATOMIC && mRight->getPropName() != ACTION) {
		s += "(";
	}
	s += mRight->toLatex();
	if (mRight->getPropName() != ATOMIC && mRight->getPropName() != ACTION) {
		s += ")";
	}

	return s;
}

bool Conjunction::isAction() {
	return mIsAction;
}

